package handler

import (
	"common/biz"
	"common/resp"
	"core/entity"
	"core/remote"
	"core/service"
	"encoding/json"
	"hall/response"
)

type UserHandler struct {
	userService *service.UserService
}

// UpdateUserAddress 修改用户地址
func (h *UserHandler) UpdateUserAddress(session *remote.Session, msg []byte) any {
	var param entity.UpdateUserAddressReq
	if err := json.Unmarshal(msg, &param); err != nil {
		return resp.F(biz.RequestDataError)
	}
	if err := h.userService.UpdateUserAddressByUid(session.Msg.Uid, param); err != nil {
		return resp.F(biz.SqlError)
	}
	res := response.UpdateUserAddressResponse{}
	res.Code = biz.OK
	res.UpdateUserData = param
	return res
}

func NewUserHandler(userService *service.UserService) *UserHandler {
	return &UserHandler{
		userService: userService,
	}
}
